from datetime import datetime
from pydantic import BaseModel
from typing import List, Optional, Any
from typing import TypeVar, Generic
from enum import IntEnum

from app.models.activity import Activity
from app.models.activity_campus import ActivityCampus

# 定义校区枚举
class CampusType(IntEnum):
    WEIJINLU = 0    # 卫津路校区
    BEIYANGYUAN = 1 # 北洋园校区
    BOTH = 2        # 两个校区都有

# 活动简略信息响应（列表）
class ActivitySuggestions(BaseModel):
    id: int
    name: str
    date_time: datetime  # 活动时间
    type_id: int
    poster: Optional[str]
    campuses: CampusType  # 校区信息
    
    class Config:
        from_attributes = True


# 活动简略信息响应（列表）
class ActivityFilter(BaseModel):
    id: int
    name: str
    date_time: datetime  # 活动时间
    # location_id: List[int]  # 校区
    submission_deadline: datetime  # 报名截止时间
    type_id: int
    poster: Optional[str]
    publisher_name: str
    publisher_avatar: Optional[str]

    class Config:
        from_attributes = True


# 活动详细信息响应
class ActivityDetail(BaseModel):
    id: int
    name: str
    activity_time: datetime
    additional_conditions: Optional[str]
    limit: int
    deadline: datetime
    location: str  # 校区
    type_id: int
    poster: Optional[str]
    publisher_name: str
    publisher_avatar: Optional[str]
    campuses: CampusType  # 改为 campuses

    class Config:
        from_attributes = True


class AdminActivityCreate(BaseModel):
    title: str
    activityTime: datetime
    deadline: datetime
    location: str
    campuses: CampusType  # 改为 campuses
    additionalRestrictions: Optional[str]
    numberLimit: str
    contentUrl: str
    type: int
    labels: List[str]
    
    class Config:
        from_attributes = True

    def into(self):
        model = Activity()
        model.name = self.title
        model.activity_time = self.activityTime
        model.additional_conditions = self.additionalRestrictions
        model.content = self.contentUrl
        model.count_limit = self.numberLimit
        model.location = self.location
        model.submission_deadline = self.deadline
        model.type = self.type
        model.campuses = int(self.campuses)  # 将枚举值转换为整数
        model.publisher = None  # 或设置为当前管理员ID
        return model


class AdminActivityUpdate(BaseModel):
    id: int
    name: Optional[str] = None
    activity_time: Optional[datetime] = None
    additional_conditions: Optional[str] = None
    content: Optional[str] = None
    count_limit: Optional[str] = None
    location: Optional[str] = None
    submission_deadline: Optional[datetime] = None
    poster: Optional[str] = None
    type: Optional[int] = None
    publisher: Optional[int] = None
    campuses: Optional[CampusType] = None
    
    class Config:
        from_attributes = True

class AdminActivityRead(BaseModel):
    id: int
    name: str
    activity_time: datetime
    additional_conditions: Optional[str]
    content: Optional[str]
    count_limit: str
    location: str
    submission_deadline: datetime
    poster: Optional[str]
    type: int
    publisher: int
    campuses: Optional[CampusType]
    
    class Config:
        from_attributes = True
